package com.eastfair.imaster.enumeration;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 排序类型枚举类
 * </p>
 *
 * @author zjn
 * @date 2021-09-02
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "SortOrderTypeEnum", description = "类型 #{MANUAL:手动排序;AUTOMATIC:自动排序-枚举")
public enum SortOrderTypeEnum implements BaseEnum {

    /**
     * MANUAL="手动排序"
     */
    MANUAL("手动排序"),
    /**
     * AUTOMATIC="自动排序"
     */
    AUTOMATIC("自动排序"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static SortOrderTypeEnum match(String val, SortOrderTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static SortOrderTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(SortOrderTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "HOST,SPEAKER", example = "HOST")
    public String getCode() {
        return this.name();
    }

}
